package com.example.demo01.commen;

import lombok.Data;

/*
* 为了统一数据类型，而做的common,
* */
@Data
public class Result {

    private static  final  String SUCCESS_CODE = "200";
    private static  final  String ERROR_CODE = "-1";

    private String code;//响应结果
    private Object data;//数据对象，后台信息
    private String msg;//错误信息

    public static Result success(){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        return result;
    }

    public static Result success(Object data){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setData(data);
        return result;
    }

    public static Result error(String  msg){
        Result result = new Result();
        result.setCode(ERROR_CODE);
        result.setMsg(msg);
        return result;
    }

    public static Result error(String code,String  msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
